package com.homegoods.videomodule.presenter;

import android.text.TextUtils;

import com.homegoods.videomodule.VideoApiUtils;
import com.homegoods.videomodule.model.FreedomCommunityModel;
import com.homegoods.videomodule.ui.view.ISetShortVideoInfo;
import com.homegoods.videomodule.ui.view.OnShortVideoListener;
import com.homegoods.videomodule.ui.view.ShortVideoView;
import com.kedll.library.mvp.BasePresenter;

/**
 * @author QiQi
 */
public class ShortVideoPresenter extends BasePresenter<ShortVideoView> implements OnShortVideoListener {
    public FreedomCommunityModel model;

    private ISetShortVideoInfo setShortVideoInfo;

    private boolean isCollect;

    public ShortVideoPresenter(ShortVideoView view) {
        super(view);
    }

    public void setShortVideoInfo(ISetShortVideoInfo setShortVideoInfo, FreedomCommunityModel model) {
        this.setShortVideoInfo = setShortVideoInfo;
        this.model = model;
    }

    /**
     * 请求短视频信息并设置信息
     */
    public void loadData() {
        if (!TextUtils.isEmpty(model.getBindSid())) {
            isCollect = false;
        } else {
            isCollect = true;
        }
        setShortVideoInfo.setLikeCount(String.valueOf(model.getCollectVol()));
        setShortVideoInfo.setCommentCount(String.valueOf(model.getReadVol()));
//        setShortVideoInfo.setHeadUrl(Constant.SERVER_URL + model.getHeadUrl());
//        setShortVideoInfo.setPosition("浙江温州");
        setShortVideoInfo.setLikeView(isCollect);
        setShortVideoInfo.setTitle(model.getTitle());
//        setShortVideoInfo.setSubTitle(model.getSource());
    }

    @Override
    public void onLikeClick() {
        if (isCollect) {
            VideoApiUtils.addVideoCollect(model.getSid(), jsonObject -> {
                isCollect = false;
                setShortVideoInfo.setLikeCount(String.valueOf(model.getCollectVol() + 1));
            }, throwable -> {

            });
        } else {
            VideoApiUtils.deletVideoCollect(model.getBindSid(), jsonObject -> {
                isCollect = true;
                setShortVideoInfo.setLikeCount(String.valueOf(model.getCollectVol() - 1));
            }, throwable -> {
            });
        }
    }

    @Override
    public void onCommentClick() {
        mView.showComment();
    }

    @Override
    public void onForwardClick() {
        mView.onForward();
    }

    @Override
    public void onAttentionClick() {
        setShortVideoInfo.setAttentionSuc();
    }
}